import requests
from requests.auth import HTTPBasicAuth
from app.services import SingletonBase
from app.utils.process_util import get_client_process
import base64
import warnings
from urllib3.exceptions import InsecureRequestWarning

# 忽略特定警告
warnings.simplefilter('ignore', InsecureRequestWarning)


class NetRequestUtil(SingletonBase):
    def __init__(self):
        lol_client = get_client_process()
        self.default_host = f"https://127.0.0.1:{lol_client.port}"
        basic_auth = HTTPBasicAuth('riot', lol_client.token)
        encoded_auth = base64.b64encode(f"{basic_auth.username}:{basic_auth.password}".encode()).decode()
        self.default_headers = {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': f'Basic {encoded_auth}'
        }
        self.session = requests.Session()
        self.session.headers.update(self.default_headers)
        # 禁用 SSL 验证
        self.session.verify = False

    def get(self, endpoint, **kwargs):
        """
        get 方法用于发送GET请求。
        post 方法用于发送POST请求。
        :param endpoint: 参数指定API的具体路径
        :param kwargs: 允许传递额外的请求参数
        :return:
        """
        url = f"{self.default_host}{endpoint}"
        # print(f"此次get请求URL = {url}")
        return self.session.get(url, **kwargs)

    def post(self, endpoint, data=None, **kwargs):
        url = f"{self.default_host}{endpoint}"
        print(f"此次get请求URL = {url}")
        return self.session.post(url, json=data, **kwargs)


# league_client_entity = get_client_process()
# net_request_util = NetRequestUtil()
# response = net_request_util.get('/lol-gameflow/v1/gameflow-phase')
# response = net_request_util.get('/lol-summoner/v1/current-summoner')
# print(f"响应json = {response.json()}")

# print('ddd' + league_client_entity.token)




